<?php

class EmbeddedMembershipFeePaymentValidatorSchema extends sfValidatorSchema
{

  protected function configure ($options = array(), $messages = array())
  {
    //    $this->addMessage ( 'area_code', 'Area code is required' );
    //    $this->addMessage ( 'call_through', 'Call through is required' );
    $this->addMessage('only_reference', 'Referenz kann nur in Zusammenhang mit Zahlungsdatum angegeben werden.');
  }

  protected function doClean ($values)
  {
    $errorSchema = new sfValidatorErrorSchema($this);
    foreach ($values as $key => $value)
    {
      $localErrorSchema = new sfValidatorErrorSchema($this);
      
      if (! $value['reference'] && ! $value['date_of_payment'])
      {
        unset($values[$key]);
        continue;
      }
      
      if ($value['reference'] && ! $value['date_of_payment'])
      {
        $localErrorSchema->addError(new sfValidatorError($this, 'only_reference'));
      }
      
      if (count($localErrorSchema))
      {
        $errorSchema->addError($localErrorSchema, (string) $key);
      }
    }
    
    if (count($errorSchema))
    {
      sfContext::getInstance()->getLogger()->log('throw error');
      throw new sfValidatorErrorSchema($this, $errorSchema);
    }
    
    return $values;
  }
}